﻿#pragma once

#include <unordered_map>
#include "../share/user_define.h"
#include "../../3rd/libjson/json.h"

/*
"props_id":101000100,
"name":"A0头盔",
"types":1,
"describe":"测试测试",
"grade":0,
"next_grade":101000101,
"cprice":[0,0,0,0,0],
"power":0,
"intelligence":0,
"agility":0,
"hp":22,
"attack":0,
"armor":3,
"magic_resist":0,
"critical":0,
"dodge":0,
"hit_ratio":0,
"armor_penetration":0,
"magic_penetration":0,
"suck_blood":2,
"tenacity":0,
"movement_speed":0,
"attack_speed":0,
"striking_distance":0,
"be_equip":[0,0],
"be_synth":[],
"syn_condition":[[102000100,5],[102000200,5]],
"syn_cost":200,
"drop_fb":0,
"icon_name":"zb_0001",
"released":1,
"lv_limit":0
*/

static const uint32_t NameStrLen = 32;
static const uint32_t size_256 = 256;
static const uint32_t max_money_type = 5;


struct UInt32_2x
{
	uint32_t mValue[2];
};

struct Equipment
{
	uint32_t mId;						// 装备ID
	char mName[NameStrLen];				// 名称
	uint32_t mTypes;					// 道具类型 1装备，2材料，3材料碎片，4金币道具，5经验道具，
										// 6英雄灵魂石，7英雄整卡，8符文，9恢复道具，10其他，11宝箱。(4,5,9,11为消耗品)

	char mDescribe[size_256];			// 描述
	uint32_t mGrade;					// 品质
	uint32_t mNextGrade;				// 进阶结果
	uint32_t mCPrice[max_money_type];	// 买入价格 [金币,钻石,龙鳞硬币,角斗士硬币,兄弟会币]
 
	double mPower;						// 力量加成
	double mIntelligence;				// 智力加成
	double mAgility;					// 敏捷加成
	double mHp;							// 生命加成
	double mAttack;						// 攻击加成
	double mArmor;						// 护甲加成
	double mMagicResist;				// 魔抗加成
	double mCritical;					// 暴击加成
	double mDodge;						// 闪避加成
	double mHitRatio;					// 命中加成
	double mArmorPenetration;			// 护甲穿透加成
	double mMagicPenetration;			// 魔法穿透加成
	double mSuckBlood;					// 吸血加成
	double mTenacity;					// 韧性
	double mMovementSpeed;				// 移动速度加成
	double mAttackSpeed;				// 攻击速度加成
	double mStrikingDistance;			// 攻击距离加成
	std::vector<UInt32_2x> mSynCondition;// 升级所需用物品列表 [id,数量]
	uint32_t mSynCost;					// 合成花费金币
	uint32_t mDropFb;					// 掉落出处 0：没有出处；1：掉落副本；2：竞技场；3：公会；4：远征
	char mIconName[NameStrLen];			// 图标名称
	uint32_t mReleased;					// 当前版本是否开放 0 : No，1：Yes
	uint32_t mLvLimit;					// 需求等级

	Equipment()
	{
		Clear();
	}

	void Clear()
	{
		_mem_zero(mName, NameStrLen);
		_mem_zero(mDescribe, size_256);
		_mem_zero(mIconName, NameStrLen);
	}
};

class EquipmentCacheData
{
public:
	static void CreateInstance(void);
	static EquipmentCacheData* GetInstance(void);

	
	~EquipmentCacheData();
public:

	bool Initialization(void);

	bool Reload(void);

	Equipment* GetData(uint32_t id);

	bool GetDataJsonString(uint32_t id, Json::Value& _jm);

	uint32_t GetDataCount(void);

private:
	EquipmentCacheData();

	void Clear(void);

	void AddData(uint32_t id, Json::Value& jm);


private:
	static EquipmentCacheData* mInstance;

	std::unordered_map<uint32_t, Equipment*> m_mapCacheData;
	uint32_t m_maxCount;
};